package com.enclave.hospital;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import com.enclave.hospital.facebook;
public class MainActivity extends Activity {
	final static ArrayList<HashMap<String, ?>> ListTimeLine = new ArrayList<HashMap<String, ?>>();
	
	private List<facebook> fbList(String url){
		// Creating JSON Parser instance
		JSONParser jParser = new JSONParser();
		// getting JSON string from URL
		List<facebook> fbarr = null ;
		JSONObject json = jParser.getJSONFromUrl(url);
		try {
			HashMap<String, Object> item=new HashMap<String, Object>();
			// Getting Array of Contacts
			contacts = json.getJSONArray(TAG_CONTACTS);
			for (int i = 0; i < contacts.length(); i++) {
				facebook fb=new facebook();
				JSONObject c = contacts.getJSONObject(i);
				fb.contentimg=R.drawable.ic_launcher;
				fb.title= c.getString(TAG_NAME);
				fbarr.add(fb);
			}

			
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return fbarr;
	}
	// url to make request
	private static String url = "http://api.androidhive.info/contacts/";
	// JSON Node names
	private static final String TAG_CONTACTS = "contacts";
	private static final String TAG_ID = "id";
	private static final String TAG_NAME = "name";
	private static final String TAG_EMAIL = "email";
	private static final String TAG_ADDRESS = "address";
	private static final String TAG_GENDER = "gender";
	private static final String TAG_PHONE = "phone";
	private static final String TAG_PHONE_MOBILE = "mobile";
	private static final String TAG_PHONE_HOME = "home";
	private static final String TAG_PHONE_OFFICE = "office";

	// contacts JSONArray
	static JSONArray contacts = null;
//	ArrayList<HashMap<String, ?>> fbTimeline=GetArray(url,R.drawable.facebookbg);
//	ArrayList<HashMap<String, ?>> twTimeline=GetArray(url,R.drawable.twitterbg);
//	
	
	ListView lv;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		lv = (ListView) findViewById(R.id.timeline);
		List<facebook>fbTimeline = fbList(url);
		ListAdapter sad=new SimpleAdapter(this, fbTimeline , R.layout.list,
				new String[] {"icon", "contentimg", "title" },
				new int[] { R.id.typeimg, R.id.contentimg,R.id.titleText });

		lv.setAdapter(sad);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}
